﻿ using System;

using Elifart.Library.Utils;
using System.Collections;

namespace Elifart.Library
{
    [Serializable]
    public class Athlete : ICloneable
    {
        #region Constructor

        public Athlete()
        {
            this.GUID = Guid.NewGuid().ToString();
        }

        public Athlete(string name, DateTime birthDate, string pictureName, string guid) : this()
        {
            this.Name = name;
            this.BirthDate = birthDate;
            this.PictureName = pictureName;
            this.GUID = guid;
        }

        #endregion

        #region Attributes and Properties

        private string _GUID;
        public string GUID
        {
            get
            {
                if (this._GUID == null)
                    this._GUID = Guid.NewGuid().ToString();
                return this._GUID;
            }
            set
            {
                string old = this._GUID;
                this._GUID = value;
                this.Notifier.RaisePropertyChanged("GUID");
            }
        }

        private string _name;
        public string Name
        {
            get { return this._name; }
            set
            {
                this._name = value;
                this.Notifier.RaisePropertyChanged("Name");
            }
        }

        private string _nickname;
        public string Nickname
        {
            get { return this._nickname; }
            set
            {
                this._nickname = value;
                this.Notifier.RaisePropertyChanged("Nickname");
            }
        }

        private DateTime _birthDate;
        public DateTime BirthDate
        {
            get { return this._birthDate; }
            set
            {
                this._birthDate = value;
                this.Notifier.RaisePropertyChanged("BirthDate");
            }
        }

        private string _pictureName;
        public string PictureName
        {
            get { return this._pictureName; }
            set
            {
                this._pictureName = value;
                this.Notifier.RaisePropertyChanged("PictureName");
            }
        }

        [NonSerialized]
        private ChangesNotifier<Athlete> _notifier;
        public ChangesNotifier<Athlete> Notifier
        {
            get
            {
                if (this._notifier == null)
                    this._notifier = new ChangesNotifier<Athlete>(this);
                return this._notifier;
            }
        }

        #endregion

        #region Overriden Methods

        public override string ToString()
        {
            return this._name;
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            Athlete cloned = new Athlete();
            cloned.BirthDate = this.BirthDate;
            cloned.Name = this.Name;
            cloned.Nickname = this.Nickname;
            cloned.PictureName = this.PictureName;

            return cloned;
        }

        #endregion
    }
}
